import 'package:architecture/os_size.dart';
import 'package:dropdown_text_field/dropdown_text_field.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../util/common.dart';
import '../../../widgets/yz_text.dart';
import 'distribute_board_controller.dart';

class DistributeBoardPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    double width = isLand() ? windowWidth * 0.25 : windowWidth * 0.7;
    return GetX<DistributeBoardController>(
        init: DistributeBoardController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(title: Text('分配棋盘')),
            body: Container(
                margin: EdgeInsets.only(top: windowHeight * 0.015),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    isLand()
                        ? Container(
                            margin: EdgeInsets.only(
                                top: windowHeight * 0.045,
                                bottom: windowHeight * 0.05,
                                right: width * 0.3),
                            child: Column(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceAround,
                                children: [
                                  Text(
                                    '流程图',
                                  ),
                                  _text('获取用户信息'),
                                  Icon(Icons.arrow_downward_rounded),
                                  _text('进入后台系统'),
                                  Icon(Icons.arrow_downward_rounded),
                                  _text('获取棋盘信息'),
                                  Icon(Icons.arrow_downward_rounded),
                                  _text('选择教室'),
                                  Icon(Icons.arrow_downward_rounded),
                                  _text('分配棋盘')
                                ]))
                        : Container(),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        MyTextField(
                          controller: controller.userNameEditingController,
                          width: width,
                          height: 70,
                          hintText: '请输入用户名或手机号',
                        ),
                        MyTextField(
                          controller: controller.passwordEditingController,
                          width: width,
                          height: 70,
                          hintText: '请输入密码',
                        ),
                        textButton(width: width, height: 45, '获取用户信息',
                            onPressed: () {
                          controller.getInfo();
                        }),
                        Offstage(
                            offstage: controller.info.value.isEmpty,
                            child: Row(
                              children: [
                                TextButton(
                                    onPressed: () {
                                      controller.copyCode();
                                    },
                                    child: Text('棋校id:' + controller.info.value,
                                        style: TextStyle(
                                            color: Colors.purpleAccent))),
                                Text(
                                  controller.area.value,
                                  style: TextStyle(color: Colors.blueAccent),
                                ),
                                TextButton(
                                    onPressed: () {
                                      controller.enterBackendSystem();
                                    },
                                    child: Text('进入后台管理系统',
                                        style: TextStyle(
                                            color: Colors.redAccent,
                                            decorationColor: Colors.redAccent,
                                            decoration:
                                                TextDecoration.underline))),
                              ],
                            )),
                        MyTextField(
                          controller: controller.boardCodeEditingController,
                          width: width,
                          height: 70,
                          hintText: '请输入棋盘编号',
                        ),
                        textButton(width: width, height: 45, '获取棋盘信息',
                            onPressed: () {
                          controller.searchBoard();
                        }),
                        Container(
                            width: width,
                            child: Text(
                              controller.detailInfo.value,
                              style: TextStyle(color: Colors.blueAccent),
                            )),
                        Row(
                          children: [
                            Text(
                              "教室:",
                              style: TextStyle(color: Colors.deepPurpleAccent),
                            ),
                            SizedBox(
                              width: 15,
                            ),
                            DropDownTextField(
                              width: width / 1.2,
                              height: 35,
                              controller: controller.areaController,
                              list: controller.areas,
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            Text(
                              '是否分配到教室',
                            ),
                            SizedBox(
                              width: 10,
                            ),
                            Checkbox(
                                value: controller.isDistribute.value,
                                onChanged: (value) {
                                  controller.changeDistribute();
                                })
                          ],
                        ),
                        textButton(width: width, height: 45, '分配到教室',
                            onPressed: () {
                          controller.distributeToClassRoom();
                        }),
                      ],
                    ),
                  ],
                )),
          );
        });
  }

  _text(String text) {
    return Container(
      color: Colors.blue.withOpacity(0.2), // 背景色（可调整透明度）
      padding: EdgeInsets.all(8), // 内边距（可选）
      child: Text(text),
    );
  }
}
